import type { RouteRecordNormalized } from 'vue-router';

const clientModules = import.meta.glob('./client-modules/*.ts', { eager: true });
const supplierModules = import.meta.glob('./supplier-modules/*.ts', {
  eager: true,
});

function formatModules(_modules: any, result: RouteRecordNormalized[]) {
  Object.keys(_modules).forEach((key) => {
    const defaultModule = _modules[key].default;
    if (!defaultModule) return;
    const moduleList = Array.isArray(defaultModule)
      ? [...defaultModule]
      : [defaultModule];
    result.push(...moduleList);
  });
  return result;
}

export const appClientRoutes: RouteRecordNormalized[] = formatModules(clientModules, []);

export const appSupplierRoutes: RouteRecordNormalized[] = formatModules(
  supplierModules,
  []
);
